﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;
using ThirdServices.AlertModel;

namespace ThirdServices.Settings
{
    class WindSettings
    {
        public static WindTypeElement CriticalWindType
        {
            get
            {
                XDocument doc = XDocument.Load("Settings/Settings.xml");
                return new WindTypeElement
                           {
                               Name = doc.Element("settings").Element("windSettings").Element("criticalwind").Attribute("name").Value,
                               BofortScale = Convert.ToInt32(doc.Element("settings").Element("windSettings").Element("criticalwind").Attribute("BofortScale").Value,CultureInfo.InvariantCulture),
                               Max = Convert.ToDouble(doc.Element("settings").Element("windSettings").Element("criticalwind").Attribute("max").Value,CultureInfo.InvariantCulture),
                               Min = Convert.ToDouble(doc.Element("settings").Element("windSettings").Element("criticalwind").Attribute("min").Value, CultureInfo.InvariantCulture),

                           };
            }
        }

        public static List<WindTypeElement> WindTypes
        {
            get
            {
                List<WindTypeElement> WindType = new List<WindTypeElement>();
                XDocument doc = XDocument.Load("Settings/Settings.xml");
                foreach(XElement xe in doc.Descendants("windSettings").Elements("windtype"))
                {
                    WindType.Add(new WindTypeElement
                                     {
                                         Name = Convert.ToString(xe.Attribute("name").Value),
                                         Max = Convert.ToDouble(xe.Attribute("max").Value,CultureInfo.InvariantCulture),
                                         Min = Convert.ToDouble(xe.Attribute("min").Value,CultureInfo.InvariantCulture),
                                         BofortScale = Convert.ToInt32(xe.Attribute("BofortScale").Value,CultureInfo.InvariantCulture)
                                     }
                        );
                }
                return WindType;
            }
        }
    }
}
